package com.lagou.controller;

import com.lagou.constant.Result;
import com.lagou.pojo.Resume;
import com.lagou.service.ResumeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * desc:
 *
 * @author tengfei wang
 * @version 1.0
 * @date Created in 16/9/2020
 */
@Controller
@RequestMapping("/resume")
public class ResumeController {

    @Resource
    private ResumeService resumeService;

    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    @ResponseBody
    public Result getAll() {
        return resumeService.getResumeList();
    }

    @RequestMapping(value = "/toAdd")
    public String addResume() {
        return "addResume";
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public Result addResume(@RequestBody Resume resume) {
        return resumeService.addResume(resume);
    }

    @RequestMapping("/update")
    @ResponseBody
    public Result toUpdate(@RequestBody Resume resume) {
        return resumeService.updateResume(resume);
    }

    @RequestMapping("/toUpdate/{id}")
    public String toUpdateResume(@PathVariable("id") Integer id, ModelMap modelMap) {
        Result resume = resumeService.getResumeById(id);
        modelMap.addAttribute("resume", resume.getResult());
        return "editResume";
    }

    @RequestMapping("/delete/{id}")
    @ResponseBody
    public Result deleteResume(@PathVariable("id") Integer id) {
        return resumeService.deleteResume(id);
    }
}
